package per.zqx.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import per.zqx.pojo.Order;
import per.zqx.pojo.OrderMessage;
import per.zqx.service.OrderMessageService;
import per.zqx.service.OrderService;

import java.util.Objects;

/**
 * OrdreTask,
 *
 * @author Sa, Zhang 2021-08-15 19:15
 */
@Component
@EnableScheduling
public class OrderTask {

    @Autowired
    OrderMessageService messageService;

    @Autowired
    OrderService orderService;

    @Scheduled(cron = "0/5 * * * * *")
    public void reSendMsg(){
        OrderMessage orderMessage = messageService.getFirstFailOrder();
        if (Objects.nonNull(orderMessage)){
            Order order = orderService.get(orderMessage.getOrderId());
            orderService.sendMessage(order);
            System.out.println("定时任务：已重新推送订单到消息队列 ===> " + order);
        }

    }
}
